<template>
	<div>
		<button class="weui-btn record" type="warning" plain="true" size="mini" @click="record()">提现记录</button>
		<view class="weui-cells weui-cells_after-title">
			<view class="weui-cell weui-cell_input">
				<view class="weui-cell__hd">
					<view class="weui-label">提现金额</view>
				</view>
				<view class="weui-cell__bd">
					<input class="weui-input" placeholder="最低提现200元" v-model="price" />
				</view>
			</view>

		</view>
		<view class="weui-btn-area">
			<button class="weui-btn" type="primary" bindtap="showTopTips" @click="cash()">确定</button>
		</view>
		
		<view class="abnor " v-if="isshowempty">
			<view class="abnor__box whbg">
				<image class="abnor__image" mode="widthFix" src="https://s10.mogucdn.com/p2/161213/upload_74hhee883cbf190e3di6cljk23679_514x260.png" style="height: 110.778px;">
				</image>
				<view class="abnor__text">您还没有提现记录哦！~</view>
				<button class="weui-btn" type="primary" bindtap="showTopTips"  size="mini"  @click="cancel()">返回</button>
			</view>
		</view>
		
		
		<div  class="cashlist">
			<view class="weui-form-preview list" v-if="recordlist.length>0 && canshow" v-for="i in recordlist" >
            <view class="weui-form-preview__hd">
                <view class="weui-form-preview__item">
                    <view class="weui-form-preview__label">金额</view>
                    <view class="weui-form-preview__value_in-hd">{{i.price}}</view>
                </view>
            </view>
            <view class="weui-form-preview__bd">
                <view class="weui-form-preview__item">
                    <view class="weui-form-preview__label">状态</view>
                    <view class="weui-form-preview__value">{{i.status==0?'未处理':i.status==1?'已通过':i.status==2?'已拒绝':'已取消'}}</view>
                </view>
               <view class="weui-form-preview__item">
                    <view class="weui-form-preview__label">交易后余额</view>
                    <view class="weui-form-preview__value">{{i.after}}</view>
                </view>
                <view class="weui-form-preview__item">
                    <view class="weui-form-preview__label">申请时间</view>
                    <view class="weui-form-preview__value">{{i.create_at}}</view>
                </view>
                <view class="weui-form-preview__item">
                    <view class="weui-form-preview__label">后台操作时间</view>
                    <view class="weui-form-preview__value">{{i.reply_at}}</view>
                </view>
                <view class="weui-form-preview__item">
                    <view class="weui-form-preview__label">提现单号</view>
                    <view class="weui-form-preview__value">{{i.refound_no}}</view>
                </view>
            </view>
            <view class="weui-form-preview__ft" v-if='i.status==0'>
                <navigator url="" @click="cancels(i.id)" class="weui-form-preview__btn weui-form-preview__btn_primary" hover-class="weui-form-preview__btn_active">取消提现</navigator>
            </view>
             <view class="weui-form-preview__ft" v-else-if='i.status==3'>
                <navigator url=""  class="weui-form-preview__btn weui-form-preview__btn_primary" hover-class="weui-form-preview__btn_active">已取消</navigator>
            </view>
            <view class="weui-form-preview__ft" v-else-if='i.status==2'>
                <navigator url=""  class="weui-form-preview__btn weui-form-preview__btn_primary" hover-class="weui-form-preview__btn_active">不可提现</navigator>
            </view>
        </view>
		</div>
	</div>
</template>

<script>
	import { requests } from "../../../static/js/network"
	export default {
		data() {
			return {
				price: '',
				recordlist: [],
				isshowempty:false,
				canshow:false
			}
		},
		onLoad(){
			Object.assign(this.$data, this.$options.data())
		},
		methods: {
			cancels(ids){
				let self = this

				requests({
					url: 'https://tp5.blver.cn/api/wechat/tixianCancel',
					method: 'POST',
					header: {
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded' // 默认值
					},
					data: {
						id:ids,
						session3rd: wx.getStorageSync('userinfo').session3rd
					},
					success: function(res) {
						console.log(res)
						wx.showModal({
									content: '提交成功，请等待审核',
									showCancel: false,
									success: function(res) {
										if(res.confirm) {

											self.canshow=false
										}
									}
								});
						
					

					}
				})
			},
			cancel(){
				this.isshowempty=false
			},
			record() {
				let self = this

				requests({
					url: 'https://tp5.blver.cn/api/wechat/tixianRecord',
					method: 'POST',
					header: {
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded' // 默认值
					},
					data: {

						session3rd: wx.getStorageSync('userinfo').session3rd
					},
					success: function(res) {
						console.log(res)
						
						if(res.data.data.length==0){
							self.isshowempty=true
						}else{
							self.canshow=true
							self.recordlist = res.data.data
						}
					

					}
				})
			},
			cash() {
				let self = this

				requests({
					url: 'https://tp5.blver.cn/api/wechat/tixian',
					method: 'POST',
					header: {
						'content-type': 'application/json',
						'content-type': 'application/x-www-form-urlencoded' // 默认值
					},
					data: {

						price: self.price,
						session3rd: wx.getStorageSync('userinfo').session3rd
					},
					success: function(res) {
						console.log(res)
						if(res.data.status == "error") {
							wx.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							})
							return
						}

						wx.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 2000
						})

					}
				})
			}
		}
	}
</script>

<style>
	.btnwidth {
		width: 95%;
	}
	
	.record {
		margin-left: 20rpx;
	}
	.whbg{background: #fff; z-index: 99;}
	.cashlist{position: fixed; top: 0; left: 0; width: 100%; background: #ccc;z-index: 99;}
</style>